package com.gph.saviorframework.echarts.test.bar;

import com.gph.saviorframework.echarts.axis.CategoryAxis;
import com.gph.saviorframework.echarts.axis.ValueAxis;
import com.gph.saviorframework.echarts.code.*;
import com.gph.saviorframework.echarts.series.Bar;
import com.gph.saviorframework.echarts.test.util.EnhancedOption;
import org.junit.Test;

public class BarTest3 {

    @Test
    public void test() {
        //地址：http://echarts.baidu.com/doc/example/bar1.html
        EnhancedOption option = new EnhancedOption();
        option.title().text("温度计式图表");
        option.tooltip().trigger(Trigger.axis).axisPointer().type(PointerType.shadow);
        option.tooltip().formatter("function (params){" +
                "            return params[0].name + '<br/>'" +
                "                   + params[0].seriesName + ' : ' + params[0].value + '<br/>'" +
                "                   + params[1].seriesName + ' : ' + (params[1].value + params[0].value);" +
                "        }");
        option.legend("Acutal", "Forecast");
        option.toolbox().show(true).feature(Tool.mark, Tool.dataView,
                Tool.restore,
                Tool.saveAsImage);

        option.calculable(true);

        option.xAxis(new CategoryAxis().data("Cosco","CMA","APL","OOCL","Wanhai","Zim"));
        option.yAxis(new ValueAxis().boundaryGap(0, 0.1).type(AxisType.value));

        Bar bar = new Bar("Acutal");
        bar.setStack("sum");
        bar.setBarCategoryGap("50%");
        bar.itemStyle().normal().color("tomato").
                barBorderColor("tomato").barBorderWidth(6).barBorderRadius(0)
                .label().position(Position.inside).show(true);
        bar.data(260, 200, 220, 120, 100, 80);

        Bar bar2 = new Bar("Forecast");
        bar2.setStack("sum");
        bar2.itemStyle().normal().color("#fff").
                barBorderColor("tomato").barBorderWidth(6).barBorderRadius(0)
                .label().position(Position.top).show(true).formatter("function (params) {" +
                "                            for (var i = 0, l = option.xAxis[0].data.length; i < l; i++) {" +
                "                                if (option.xAxis[0].data[i] == params.name) {" +
                "                                    return option.series[0].data[i] + params.value;" +
                "                                }" +
                "                            }" +
                "                        }").textStyle().color("tomato");
        bar2.data(40, 80, 50, 80, 80, 70);
        option.series(bar, bar2);
        option.exportToHtml("bar3.html");
        option.view();
    }
}
